/**********************************************************************************************************
** 驱动文件：	jmkt-ACM03U1.c
** 驱动类型：	jmkt
** 设备名称：	精密空调
** 设备型号：	ACM03U1
** 设备品牌：	艾默生
** 设备协议：	电总协议
** 驱动描述：	本协议是《监控行标第三部分：智能设备通信协议》（电总协议）的简化版本VER2.1，适用于艾默生网络能源有限公司精密空调ACM03U1控制器监控。
** 生成日期：	2019-02-26 23:17:54
**********************************************************************************************************/
#include "Includes.h"


/**********************************************************************************************************
* 定义设备数据点变量结构
**********************************************************************************************************/
typedef struct{
	Var returnAirTemperature;					//回风温度
	Var returnAirHumidity;						//回风湿度
	Var setTemperature;							//温度设定点
	Var setHumidity;							//湿度设定点
	Var APhaseVoltage;							//A相电压
	Var BPhaseVoltage;							//B相电压
	Var CPhaseVoltage;							//C相电压
	Var powerFrequency;							//电源频率
	Var onoff;									//开关机状态
	Var fanStatus;								//风机状态
	Var coolingStatus;							//制冷状态
	Var heatingStatus;							//加热状态
	Var humidificationStatus;					//加湿状态
	Var dehumidificationStatus;					//除湿状态
	Var operatingMode;							//空调运行模式
	Var compressor1PressureAlarm;				//压缩机1高/低压报警
	Var compressor2PressureAlarm;				//压缩机2高/低压报警
	Var exhaust1TemperatureAlarm;				//排气1高/低温报警
	Var exhaust2TemperatureAlarm;				//排气2高/低温报警
	Var temperatureAlarm;						//高/低温报警
	Var humidityAlarm;							//高/低湿报警
	Var coil1FreezeAlarm;						//盘管1冻结报警
	Var coil2FreezeAlarm;						//盘管2冻结报警
	Var aRoadWaterLoss;							//A路水流丢失
	Var bRoadWaterLoss;							//B路水流丢失
	Var lowPressureSensor1Failure;				//低压传感器1故障
	Var lowPressureSensor2Failure;				//低压传感器2故障
	Var NTC1Failure;							//NTC1故障报警
	Var NTC2Failure;							//NTC2故障报警
	Var NTC3Failure;							//NTC3故障报警
	Var NTC4Failure;							//NTC4故障报警
	Var fanFailure;								//风机故障报警
	Var airflowLoss;							//气流丢失报警
	Var filterPlugAlarm;						//过滤网堵报警
	Var remoteShutdownAlarm;					//远程关机报警
	Var tempHumiBoardFailure;					//温湿度检测板故障
	Var smokeAlarm;								//烟感报警
	Var filterMaintenanceAlarm;					//过滤网维护报警
	Var electricHeaterFailure;					//电加热故障
	Var powerFailureAlarm;						//电源故障报警
	Var floorOverflowAlarm;						//地板溢水报警
	Var airSupplyHighTempAlarm;					//送风高温报警
	Var windPressureSensorFailure;				//风压传感器故障
	Var humidifierHighWaterLevelAlarm;			//加湿器高水位报警
	Var groupControlModeSlaveLost;				//群控模式从机丢失
	Var groupControlModeHostLost;				//群控模式主机丢失
	Var fanRunTimeout;							//风机运行超时
	Var compressor1RunTimeout;					//压缩机1运行超时
	Var compressor2RunTimeout;					//压缩机2运行超时
	Var heater1RunTimeout;						//加热器1运行超时
	Var heater2RunTimeout;						//加热器2运行超时
	Var humidifierRunTimeout;					//加湿器运行超时
}Data_Struct;									//定义变量结构


/**********************************************************************************************************
* 设备数据点变量属性声明
**********************************************************************************************************/
const static Var_Property_Def var_attr[] = {
	{
		FLOAT,
		0,
		READONLY,
		"returnAirTemperature",
		"回风温度",
		"℃",
		"回风温度",
		0,
		0,
		"回风温度过高",
		"回风温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"returnAirHumidity",
		"回风湿度",
		"%",
		"回风湿度",
		0,
		0,
		"回风湿度过高",
		"回风湿度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"setTemperature",
		"温度设定点",
		"℃",
		"温度设定点",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"setHumidity",
		"湿度设定点",
		"%",
		"温度设定点",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"APhaseVoltage",
		"A相电压",
		"V",
		"A相电压",
		0,
		0,
		"A相电压过高",
		"A相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"BPhaseVoltage",
		"B相电压",
		"V",
		"B相电压",
		0,
		0,
		"B相电压过高",
		"B相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"CPhaseVoltage",
		"C相电压",
		"V",
		"C相电压",
		0,
		0,
		"C相电压过高",
		"C相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"powerFrequency",
		"电源频率",
		"Hz",
		"电源频率",
		0,
		0,
		"电源频率过高",
		"电源频率过低",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"onoff",
		"开关机状态",
		"",
		"空调开关机状态：运行、待机、关机、远程关机",
		0,
		0,
		"空调关机",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"fanStatus",
		"风机状态",
		"",
		"风机状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"coolingStatus",
		"制冷状态",
		"",
		"制冷状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heatingStatus",
		"加热状态",
		"",
		"加热状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humidificationStatus",
		"加湿状态",
		"",
		"加湿状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"dehumidificationStatus",
		"除湿状态",
		"",
		"除湿状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"operatingMode",
		"空调运行模式",
		"",
		"空调运行模式：单机、群控0模式、群控1模式、群控2模式、群控3模式",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor1PressureAlarm",
		"压缩机1高/低压报警",
		"",
		"压缩机1高压、低压报警：0-无报警；1-高压报警；2-低压报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor2PressureAlarm",
		"压缩机2高/低压报警",
		"",
		"压缩机2高压、低压报警：0-无报警；1-高压报警；2-低压报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"exhaust1TemperatureAlarm",
		"排气1高/低温报警",
		"",
		"排气1高、低温报警：0-无报警；1-高温报警；2-低温报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"exhaust2TemperatureAlarm",
		"排气2高/低温报警",
		"",
		"排气2高、低温报警：0-无报警；1-高温报警；2-低温报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"temperatureAlarm",
		"高/低温报警",
		"",
		"高温、低温报警：0-无报警；1-高温报警；2-低温报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humidityAlarm",
		"高/低湿报警",
		"",
		"高湿、低湿报警：0-无报警；1-髙湿报警；2-低湿报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"coil1FreezeAlarm",
		"盘管1冻结报警",
		"",
		"盘管1冻结报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"coil2FreezeAlarm",
		"盘管2冻结报警",
		"",
		"盘管2冻结报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"aRoadWaterLoss",
		"A路水流丢失",
		"",
		"A路水流丢失：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"bRoadWaterLoss",
		"B路水流丢失",
		"",
		"B路水流丢失：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"lowPressureSensor1Failure",
		"低压传感器1故障",
		"",
		"低压传感器1故障：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"lowPressureSensor2Failure",
		"低压传感器2故障",
		"",
		"低压传感器2故障：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"NTC1Failure",
		"NTC1故障报警",
		"",
		"NTC1故障报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"NTC2Failure",
		"NTC2故障报警",
		"",
		"NTC2故障报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"NTC3Failure",
		"NTC3故障报警",
		"",
		"NTC3故障报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"NTC4Failure",
		"NTC4故障报警",
		"",
		"NTC4故障报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"fanFailure",
		"风机故障报警",
		"",
		"风机故障报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"airflowLoss",
		"气流丢失报警",
		"",
		"气流丢失报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"filterPlugAlarm",
		"过滤网堵报警",
		"",
		"过滤网堵报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"remoteShutdownAlarm",
		"远程关机报警",
		"",
		"远程关机报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"tempHumiBoardFailure",
		"温湿度检测板故障",
		"",
		"温湿度检测板故障：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"smokeAlarm",
		"烟感报警",
		"",
		"烟感报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"filterMaintenanceAlarm",
		"过滤网维护报警",
		"",
		"过滤网维护报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"electricHeaterFailure",
		"电加热故障",
		"",
		"电加热故障：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"powerFailureAlarm",
		"电源故障报警",
		"",
		"电源故障报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"floorOverflowAlarm",
		"地板溢水报警",
		"",
		"地板溢水报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"airSupplyHighTempAlarm",
		"送风高温报警",
		"",
		"送风高温报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"windPressureSensorFailure",
		"风压传感器故障",
		"",
		"风压传感器故障：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humidifierHighWaterLevelAlarm",
		"加湿器高水位报警",
		"",
		"加湿器高水位报警：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"groupControlModeSlaveLost",
		"群控模式从机丢失",
		"",
		"群控模式从机丢失：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"groupControlModeHostLost",
		"群控模式主机丢失",
		"",
		"群控模式主机丢失：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"fanRunTimeout",
		"风机运行超时",
		"",
		"风机运行超时：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor1RunTimeout",
		"压缩机1运行超时",
		"",
		"压缩机1运行超时：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor2RunTimeout",
		"压缩机2运行超时",
		"",
		"压缩机2运行超时：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heater1RunTimeout",
		"加热器1运行超时",
		"",
		"加热器1运行超时：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heater2RunTimeout",
		"加热器2运行超时",
		"",
		"加热器2运行超时：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humidifierRunTimeout",
		"加湿器运行超时",
		"",
		"加湿器运行超时：0-无报警；1-有报警",
		0,
		0,
		"有报警",
		"",
		0,
		0
	}
};


/**********************************************************************************************************
* 函数名称： static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
* 函数说明： 生成获取传感器数据指令
* 输入参数： 指令索引，传感器地址，变量结构体指针,以及指令缓存区指针,指令长度
* 返回参数： 无
**********************************************************************************************************/
static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
{
	unsigned short i,n,sum;
	switch(index)
	{
		case 0:	//获取模拟量数据	7E 32 31 30 31 36 30 34 32 30 30 30 30 46 44 42 30 0D
			*len = sprintf(cmd,"\x7E\x32\x31\x30\x31\x36\x30\x34\x32\x30\x30\x30\x30\x46\x44\x42\x30\x0D");
			break;
		case 1:	//获取系统参数  	7E 32 31 30 31 36 30 34 37 30 30 30 30 46 44 41 42 0D
			*len = sprintf(cmd,"\x7E\x32\x31\x30\x31\x36\x30\x34\x37\x30\x30\x30\x30\x46\x44\x41\x42\x0D");
			break;
		case 2:	//获取机组状态		7E 32 31 30 31 36 30 38 32 30 30 30 30 46 44 41 43 0D
			*len = sprintf(cmd,"\x7E\x32\x31\x30\x31\x36\x30\x38\x32\x30\x30\x30\x30\x46\x44\x41\x43\x0D");
			break;
		case 3:	//获取运行模式和报警状态		7E 32 31 30 31 36 30 38 35 30 30 30 30 46 44 41 43 0D
			*len = sprintf(cmd,"\x7E\x32\x31\x30\x31\x36\x30\x38\x35\x30\x30\x30\x30\x46\x44\x41\x43\x0D");
			break;
		default:
			break;
	}
	if(*len){
		n	= (addr>>4)&0x000F;
		cmd[3] = n>9?(n-10+'A'):n+'0';
		n	= addr&0x000F;
		cmd[4] = n>9?(n-10+'A'):n+'0';			

		for(i=1,sum=0; i<13; i++){
			sum += cmd[i];
		}
		sum = sum%65536;
		sum = ~sum + 1;
		n	= (sum>>12)&0x000F;
		cmd[13] = n>9?(n-10+'A'):n+'0';
		n	= (sum>>8)&0x000F;
		cmd[14] = n>9?(n-10+'A'):n+'0';			
		n	= (sum>>4)&0x000F;
		cmd[15] = n>9?(n-10+'A'):n+'0';	
		n	= sum&0x000F;
		cmd[16] = n>9?(n-10+'A'):n+'0';	
	}
}


/**********************************************************************************************************
* 函数名称： static int parse_fun(short index, int addr, void *data, char *buf, short len)
* 函数说明： 解析传感器响应的数据，并写入数据库
* 输入参数： 解析索引,传感器地址，变量结构体指针，以及响应数据缓存取指针，响应数据长度
* 返回参数： 返回解析结果，返回0成功，返回1失败
**********************************************************************************************************/
static int parse_fun(short index, int addr, void *data, char *buf, short len)
{
	union{
		unsigned short 	int16;
      	unsigned char  	buf[2];
    }Num;	//数据类型转换
	unsigned short i,j, sum;	
	Data_Struct	*d = (Data_Struct*)data;

	if(buf!=NULL && len>0 && buf[0]==0x7E && buf[len-1]==0x0D)
	{
		//开始校验数据的完整性
		for(i=1,sum=0; i<len-5; i++){
			sum += buf[i];
		}
		sum = sum%65536;
		sum = ~sum + 1;
		//将数据转化为十六进制
		for(i=1,j=1; i<len-1; j++){
			if(buf[i]==0x20) buf[j] = 0;
			else buf[j] = (buf[i] >= '0' && buf[i] <= '9') ? buf[i] - '0' : (buf[i]|32) - 'a' + 10;	
			i++;
			buf[j] <<= 4;
			if(buf[i]==0x20) buf[j]|= 0;
			else buf[j]|= (buf[i] >= '0' && buf[i] <= '9') ? buf[i] - '0' : (buf[i]|32) - 'a' + 10;
			i++;
		}
		Num.buf[1] = buf[j-2];
		Num.buf[0] = buf[j-1];	
		if(sum == Num.int16){
			sum = buf[5]&0x0F;
			sum+= (buf[6]>>4)&0x0F;
			sum+= buf[6]&0x0F;		
			sum = sum%16;
			sum = ~sum + 1;	
			sum = sum&0x0F;
			if(sum != ((buf[5]>>4)&0x0F)){
				return 1;
			}
		}
		else{
			return 1;
		}	
		//校验处理完毕，开始解析数据

		switch(index){
			case 0:
				Num.buf[1] = buf[7];
				Num.buf[0] = buf[8];
				d->returnAirTemperature.value.fnum = Num.int16 * 0.1;
				Num.buf[1] = buf[9];
				Num.buf[0] = buf[10];
				d->returnAirHumidity.value.fnum = Num.int16 * 0.1;					
				Num.buf[1] = buf[11];
				Num.buf[0] = buf[12];
				d->APhaseVoltage.value.fnum = Num.int16 * 0.1;
				Num.buf[1] = buf[13];
				Num.buf[0] = buf[14];
				d->BPhaseVoltage.value.fnum = Num.int16 * 0.1;				
				Num.buf[1] = buf[15];
				Num.buf[0] = buf[16];
				d->CPhaseVoltage.value.fnum = Num.int16 * 0.1;				
				Num.buf[1] = buf[19];
				Num.buf[0] = buf[20];
				d->powerFrequency.value.fnum = Num.int16 * 0.1;	
				break;
			case 1:
				Num.buf[1] = buf[7];
				Num.buf[0] = buf[8];
				d->setTemperature.value.fnum = Num.int16 * 0.1;
				Num.buf[1] = buf[9];
				Num.buf[0] = buf[10];
				d->setHumidity.value.fnum = Num.int16 * 0.1;				
				break;
			case 2:
				if(buf[7]==0) 		d->onoff.value.str = "运行";
				else if(buf[7]==1)	d->onoff.value.str = "待机";
				else if(buf[7]==2)	d->onoff.value.str = "关机";
				else if(buf[7]==3)	d->onoff.value.str = "远程关机";
				else				d->onoff.value.str = "未知";
				Set_Var_Status(&d->onoff, (buf[7]==0||buf[7]==1)?Normal:Alarm, NULL);

				d->fanStatus.value.str					  = buf[8 ]==1?"运行":"停止";
				Set_Var_Status(&d->fanStatus,				buf[8 ]==1?ON:OFF, NULL);
				d->coolingStatus.value.str				  = buf[22]==1?"运行":"停止";
				Set_Var_Status(&d->coolingStatus,			buf[22]==1?ON:OFF, NULL);
				d->heatingStatus.value.str				  = buf[23]==1?"运行":"停止";
				Set_Var_Status(&d->heatingStatus,			buf[23]==1?ON:OFF, NULL);
				d->dehumidificationStatus.value.str 	  = buf[24]==1?"运行":"停止";
				Set_Var_Status(&d->dehumidificationStatus,	buf[24]==1?ON:OFF, NULL);			
				d->humidificationStatus.value.str		  = buf[25]==1?"运行":"停止";
				Set_Var_Status(&d->humidificationStatus,	buf[25]==1?ON:OFF, NULL);
				break;
			case 3:
				if(buf[7]==0) 		d->operatingMode.value.str = "单机";
				else if(buf[7]==1)	d->operatingMode.value.str = "群控0模式";
				else if(buf[7]==2)	d->operatingMode.value.str = "群控1模式";
				else if(buf[7]==3)	d->operatingMode.value.str = "群控2模式";
				else if(buf[7]==4)	d->operatingMode.value.str = "群控3模式";				
				else				d->operatingMode.value.str = "未知";

				if(buf[8]&0x02){
					d->compressor1PressureAlarm.value.str	= "高压报警";
					Set_Var_Status(&d->compressor1PressureAlarm, Alarm, "高压报警");
				}
				else if(buf[8]&0x08){
					d->compressor1PressureAlarm.value.str	= "低压报警";
					Set_Var_Status(&d->compressor1PressureAlarm, Alarm, "低压报警");					
				}
				else{
					d->compressor1PressureAlarm.value.str	= "无报警";
					Set_Var_Status(&d->compressor1PressureAlarm, Normal, "无报警");
				}
				
				if(buf[8]&0x04){
					d->compressor2PressureAlarm.value.str	= "高压报警";
					Set_Var_Status(&d->compressor2PressureAlarm, Alarm, "高压报警");
				}
				else if(buf[8]&0x10){
					d->compressor2PressureAlarm.value.str	= "低压报警";
					Set_Var_Status(&d->compressor2PressureAlarm, Alarm, "低压报警");					
				}
				else{
					d->compressor2PressureAlarm.value.str	= "无报警";
					Set_Var_Status(&d->compressor2PressureAlarm, Normal, "无报警");
				}				
				
				if(buf[8]&0x20){
					d->exhaust1TemperatureAlarm.value.str	= "高温报警";
					Set_Var_Status(&d->exhaust1TemperatureAlarm, Alarm, "高温报警");
				}
				else if(buf[16]&0x40){
					d->exhaust1TemperatureAlarm.value.str	= "低温报警";
					Set_Var_Status(&d->exhaust1TemperatureAlarm, Alarm, "低温报警");					
				}
				else{
					d->exhaust1TemperatureAlarm.value.str	= "无报警";
					Set_Var_Status(&d->exhaust1TemperatureAlarm, Normal, "无报警");
				}				
				
				if(buf[8]&0x40){
					d->exhaust2TemperatureAlarm.value.str	= "高温报警";
					Set_Var_Status(&d->exhaust2TemperatureAlarm, Alarm, "高温报警");
				}
				else if(buf[16]&0x80){
					d->exhaust2TemperatureAlarm.value.str	= "低温报警";
					Set_Var_Status(&d->exhaust2TemperatureAlarm, Alarm, "低温报警");					
				}
				else{
					d->exhaust2TemperatureAlarm.value.str	= "无报警";
					Set_Var_Status(&d->exhaust2TemperatureAlarm, Normal, "无报警");
				}				

				if(buf[9]&0x40){
					d->temperatureAlarm.value.str	= "高温报警";
					Set_Var_Status(&d->temperatureAlarm, Alarm, "高温报警");
				}
				else if(buf[9]&0x80){
					d->temperatureAlarm.value.str	= "低温报警";
					Set_Var_Status(&d->temperatureAlarm, Alarm, "低温报警");						
				}
				else{
					d->temperatureAlarm.value.str	= "无报警";
					Set_Var_Status(&d->temperatureAlarm, Normal, "无报警");
				}

				if(buf[10]&0x01){
					d->humidityAlarm.value.str	= "高湿报警";
					Set_Var_Status(&d->humidityAlarm, Alarm, "高湿报警");
				}
				else if(buf[10]&0x02){
					d->humidityAlarm.value.str	= "低湿报警";
					Set_Var_Status(&d->humidityAlarm, Alarm, "低湿报警");						
				}
				else{
					d->humidityAlarm.value.str	= "无报警";
					Set_Var_Status(&d->humidityAlarm, Normal, "无报警");
				}					

				d->coil1FreezeAlarm.value.str			  = buf[8 ]&0x80?"有报警":"无报警";
				Set_Var_Status(&d->coil1FreezeAlarm,		buf[8 ]&0x80?Alarm:Normal, NULL);
				d->coil2FreezeAlarm.value.str			  = buf[9 ]&0x01?"有报警":"无报警";
				Set_Var_Status(&d->coil2FreezeAlarm,		buf[9 ]&0x01?Alarm:Normal, NULL);
				
				d->aRoadWaterLoss.value.str 	  		  = buf[17]&0x10?"有报警":"无报警";
				Set_Var_Status(&d->aRoadWaterLoss,			buf[17]&0x10?Alarm:Normal, NULL);				
				d->bRoadWaterLoss.value.str				  = buf[17]&0x20?"有报警":"无报警";
				Set_Var_Status(&d->bRoadWaterLoss,			buf[17]&0x20?Alarm:Normal, NULL);

				d->lowPressureSensor1Failure.value.str 	  = buf[18]&0x04?"有报警":"无报警";
				Set_Var_Status(&d->lowPressureSensor1Failure,buf[18]&0x04?Alarm:Normal, NULL);	
				d->lowPressureSensor2Failure.value.str	  = buf[18]&0x08?"有报警":"无报警";
				Set_Var_Status(&d->lowPressureSensor2Failure,buf[18]&0x08?Alarm:Normal, NULL);

				d->NTC1Failure.value.str				  = buf[13]&0x04?"有报警":"无报警";
				Set_Var_Status(&d->NTC1Failure,				buf[13]&0x04?Alarm:Normal, NULL);
				d->NTC2Failure.value.str				  = buf[13]&0x08?"有报警":"无报警";
				Set_Var_Status(&d->NTC2Failure,				buf[13]&0x08?Alarm:Normal, NULL);
				d->NTC3Failure.value.str				  = buf[13]&0x10?"有报警":"无报警";
				Set_Var_Status(&d->NTC3Failure,				buf[13]&0x10?Alarm:Normal, NULL);
				d->NTC4Failure.value.str				  = buf[13]&0x20?"有报警":"无报警";
				Set_Var_Status(&d->NTC4Failure,				buf[13]&0x20?Alarm:Normal, NULL);

				d->fanFailure.value.str					  = buf[9 ]&0x0E?"有报警":"无报警";
				Set_Var_Status(&d->fanFailure,				buf[9 ]&0x0E?Alarm:Normal, NULL);
				d->airflowLoss.value.str				  = buf[10]&0x20?"有报警":"无报警";
				Set_Var_Status(&d->fanFailure,				buf[10]&0x20?Alarm:Normal, NULL);				
				d->filterPlugAlarm.value.str			  = buf[10]&0x40?"有报警":"无报警";
				Set_Var_Status(&d->filterPlugAlarm,			buf[10]&0x40?Alarm:Normal, NULL);
				d->remoteShutdownAlarm.value.str 		  = buf[10]&0x80?"有报警":"无报警";
				Set_Var_Status(&d->remoteShutdownAlarm,		buf[10]&0x80?Alarm:Normal, NULL);					
				d->tempHumiBoardFailure.value.str		  = buf[11]&0x01?"有报警":"无报警";
				Set_Var_Status(&d->tempHumiBoardFailure,	buf[11]&0x01?Alarm:Normal, NULL);
				d->smokeAlarm.value.str 				  = buf[11]&0x06?"有报警":"无报警";
				Set_Var_Status(&d->smokeAlarm,				buf[11]&0x06?Alarm:Normal, NULL);
				d->filterMaintenanceAlarm.value.str		  = buf[18]&0x10?"有报警":"无报警";
				Set_Var_Status(&d->filterMaintenanceAlarm,	buf[18]&0x10?Alarm:Normal, NULL);
				d->electricHeaterFailure.value.str		  = buf[18]&0x20?"有报警":"无报警";
				Set_Var_Status(&d->electricHeaterFailure,	buf[18]&0x20?Alarm:Normal, NULL);
				d->powerFailureAlarm.value.str			  =(buf[12]&0xF8||buf[13]&0x01)?"有报警":"无报警";
				Set_Var_Status(&d->powerFailureAlarm,	   (buf[12]&0xF8||buf[13]&0x01)?Alarm:Normal, NULL);
				
				d->floorOverflowAlarm.value.str			  = buf[13]&0x02?"有报警":"无报警";
				Set_Var_Status(&d->floorOverflowAlarm,		buf[13]&0x02?Alarm:Normal, NULL);				
				d->airSupplyHighTempAlarm.value.str		  = buf[17]&0x08?"有报警":"无报警";
				Set_Var_Status(&d->airSupplyHighTempAlarm,	buf[17]&0x08?Alarm:Normal, NULL);					
				d->windPressureSensorFailure.value.str	  = buf[17]&0x40?"有报警":"无报警";
				Set_Var_Status(&d->windPressureSensorFailure,buf[17]&0x40?Alarm:Normal, NULL);					
				d->humidifierHighWaterLevelAlarm.value.str= buf[17]&0x80?"有报警":"无报警";
				Set_Var_Status(&d->humidifierHighWaterLevelAlarm, buf[17]&0x80?Alarm:Normal, NULL);
				d->groupControlModeSlaveLost.value.str	  = buf[17]&0x02?"有报警":"无报警";
				Set_Var_Status(&d->groupControlModeSlaveLost,buf[18]&0x02?Alarm:Normal, NULL);
				d->groupControlModeHostLost.value.str	  = buf[17]&0x04?"有报警":"无报警";
				Set_Var_Status(&d->groupControlModeHostLost,buf[18]&0x04?Alarm:Normal, NULL);

				d->fanRunTimeout.value.str				  = buf[11]&0x20?"有报警":"无报警";
				Set_Var_Status(&d->fanRunTimeout,			buf[11]&0x20?Alarm:Normal, NULL);
				d->compressor1RunTimeout.value.str		  = buf[11]&0x40?"有报警":"无报警";
				Set_Var_Status(&d->compressor1RunTimeout,	buf[11]&0x40?Alarm:Normal, NULL);
				d->compressor2RunTimeout.value.str		  = buf[11]&0x80?"有报警":"无报警";
				Set_Var_Status(&d->compressor2RunTimeout,	buf[11]&0x80?Alarm:Normal, NULL);d->
				heater1RunTimeout.value.str				  = buf[12]&0x01?"有报警":"无报警";
				Set_Var_Status(&d->heater1RunTimeout,		buf[12]&0x01?Alarm:Normal, NULL);
				d->heater2RunTimeout.value.str			  = buf[12]&0x02?"有报警":"无报警";
				Set_Var_Status(&d->heater2RunTimeout,		buf[12]&0x02?Alarm:Normal, NULL);
				d->humidifierRunTimeout.value.str		  = buf[12]&0x04?"有报警":"无报警";
				Set_Var_Status(&d->humidifierRunTimeout,	buf[12]&0x04?Alarm:Normal, NULL);				

				break;
			default:
				break;
		}
		return 0;
	}
	return 1;
}


/**********************************************************************************************************
* 函数名称： void jmkt_ACM03U1_Registration(void)
* 函数说明： 艾默生精密空调驱动注册
* 输入参数： 无
* 返回参数： 无
**********************************************************************************************************/
void jmkt_ACM03U1_Registration(void)
{
	DeviceRegWithResTimeout(
		"jmkt",													//设备类型
		"精密空调",												//设备名称（导航栏默认显示名称）
		"ACM03U1",												//设备型号
		"本协议是《监控行标第三部分：智能设备通信协议》（电总协议）的简化版本，适用于艾默生网络能源有限公司精密空调ACM03U1控制器监控。",//驱动描述
		var_attr,												//变量属性声明
		sizeof(Data_Struct),									//变量结构体空间大小
		cmd_fun,												//发送指令生成函数
		parse_fun,												//数据解析函数
		500														//设备响应超时时间
	);
#if 0
	#define	CMD1	"\x7E\x32\x31\x30\x31\x36\x30\x34\x32\x30\x30\x30\x30\x46\x44\x42\x30\x0D"
	#define	RSP1	"\x7E\x32\x31\x30\x31\x36\x30\x30\x30\x31\x30\x33\x43\x30\x30\x44\x32\x30\x31\x43\x42\x30\x38\x41\x37\x30\x39\x30\x35\x30\x38\x41\x37\x30\x30\x30\x31\x30\x31\x46\x34\x30\x30\x44\x43\x46\x45\x36\x36\x30\x30\x46\x46\x46\x45\x36\x36\x30\x30\x30\x34\x30\x30\x30\x34\x30\x31\x39\x33\x30\x30\x30\x34\x46\x30\x44\x46\x0D"
	#define	CMD2	"\x7E\x32\x31\x30\x31\x36\x30\x34\x37\x30\x30\x30\x30\x46\x44\x41\x42\x0D"
	#define	RSP2	"\x7E\x32\x31\x30\x31\x36\x30\x30\x30\x35\x30\x31\x41\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x43\x38\x30\x30\x31\x45\x30\x31\x39\x30\x30\x30\x33\x32\x30\x30\x46\x38\x37\x46\x0D"
	#define	CMD3	"\x7E\x32\x31\x30\x31\x36\x30\x38\x32\x30\x30\x30\x30\x46\x44\x41\x43\x0D"
	#define	RSP3	"\x7E\x32\x31\x30\x31\x36\x30\x30\x30\x38\x30\x32\x36\x30\x30\x30\x31\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x46\x36\x38\x35\x0D"					
	#define	CMD4	"\x7E\x32\x31\x30\x31\x36\x30\x38\x35\x30\x30\x30\x30\x46\x44\x41\x39\x0D"
	#define	RSP4	"\x7E\x32\x31\x30\x31\x36\x30\x30\x30\x37\x30\x31\x38\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x46\x39\x32\x36\x0D"	
	VirtualFrameRegistration(CMD1, sizeof(CMD1)-1, RSP1, sizeof(RSP1)-1);
//	VirtualFrameRegistration(CMD2, sizeof(CMD2)-1, RSP2, sizeof(RSP2)-1);
	VirtualFrameRegistration(CMD3, sizeof(CMD3)-1, RSP3, sizeof(RSP3)-1);
	VirtualFrameRegistration(CMD4, sizeof(CMD4)-1, RSP4, sizeof(RSP4)-1);		
#endif	
}

